import { BasicForm, FormSchema, useForm } from "@/components/Form";
import { Button, message } from "antd";
import "./index.less";
import { depositHistoryApi } from "@/api/Hospitalization/hospitalizationExpenses/depositHistory";
import { useTranslation } from "react-i18next";

const index = ({ record, setPageFn }: any) => {
	const { t } = useTranslation();
	const en_vi = "Hospitalization.Hospitalization.depositHistory";
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.patCardno`),
			field: "patCardno",
			component: "Input",
			componentProps: {
				disabled: true
			}
		},
		{
			label: t(`${en_vi}.paymentType`),
			field: "pmtType",
			component: "Select",
			componentProps: {
				options: [
					{
						label: t(`${en_vi}.cash`),
						value: 1
					},
					{
						label: t(`${en_vi}.alipay`),
						value: 2
					},
					{
						label: t(`${en_vi}.wechat`),
						value: 3
					}
				]
			}
		},
		{
			label: t(`${en_vi}.paymentAmountCny`),
			field: "pmtFee",
			component: "InputNumber"
		},
		{
			label: t(`${en_vi}.incomeExpenseType`),
			field: "feeType",
			component: "RadioGroup",
			componentProps: {
				options: [
					{
						label: t(`${en_vi}.recharge`),
						value: 1
					},
					{
						label: t(`${en_vi}.withdrawal`),
						value: 2
					}
				]
			}
		}
	];
	const [register, { validateFields, setFieldsValue }] = useForm({
		schemas,
		labelWidth: 100,
		baseColProps: {
			span: 24
		},
		initialValues: {
			patCardno: record.patCardno
		}
	});
	const submit = async () => {
		const valuesForm = await validateFields();
		valuesForm.patId = record.patientId;
		const res = await depositHistoryApi.depositHistoryCreate(valuesForm);
		console.log(res);
		if (!res) message.error(t("kevin_ui.addFailed"));
		message.success(t("kevin_ui.addedSuccessfully"));
		setFieldsValue({});
		setPageFn("1");
	};
	return (
		<div className="addDeposit">
			<BasicForm register={register}></BasicForm>
			<div className="button">
				<Button onClick={submit} type="primary" block>
					{t(`${en_vi}.submit`)}
				</Button>
			</div>
		</div>
	);
};
export default index;
